home *** CD-ROM | disk | FTP | other *** search
- /* this file interfaces between the apple interface code and the stuff that actually
- does the hard work!
- */
-
- #include <stdio.h>
- #include <assert.h>
- #include <string.h>
- #include <stdlib.h>
- #include "SCSIPrototypes.h"
- #include "SCSIDefines.h"
-
- #include "Defines.h"
- #include "Prototypes.h"
-
- Str255 gParentDir;
- BUFFER *gBufferPtr;
-
- void Initialize(void)
- {
- short status;
- short id;
- char name[STRING];
-
- status = FindTape(name, &id);
- if (status == OK) printf("Tape %s found at %hd\n", name, id);
- else
- {
- printf("No tape devices found\n");
- exit(0);
- }
- }
-
- void DoWork(short selection)
- {
- StandardFileReply reply;
- short fileRefNum;
- char buffer[BLOCKSIZE];
- long count;
-
- switch (selection)
- {
- case WRITE_TAPE_ITEM: /* write to tape */
-
- StandardGetFolder ("\pSelect folder to copy from:", &reply);
- if (!reply.sfGood) break;
-
- Rewind();
- gBufferPtr = BufferOpen();
-
- FullFileName(gParentDir, NULL,
- reply.sfFile.vRefNum, reply.sfFile.parID);
-
- SearchDirectory(reply.sfFile.parID, reply.sfFile.vRefNum, WriteFile, WriteFile);
- WriteEOF();
- BufferClose(gBufferPtr);
-
- break;
-
- case READ_TAPE_ITEM: /* read from tape */
-
- StandardGetFolder ("\pSelect folder to copy to:", &reply);
- if (!reply.sfGood) break;
-
- Rewind();
- gBufferPtr = BufferOpen();
-
- FullFileName(gParentDir, NULL,
- reply.sfFile.vRefNum, reply.sfFile.parID);
-
- while (ReadFile() == OK);
- BufferClose(gBufferPtr);
-
- break;
-
- case LIST_TAPE_ITEM: /* list tape */
-
- Rewind();
- gBufferPtr = BufferOpen();
- while (ListFile() == OK);
- BufferClose(gBufferPtr);
-
- break;
-
- case DUMP_TAPE_ITEM: /* read tape to file */
-
- StandardPutFile("\pWrite disk file to tape:", "\pTape Dump", &reply);
-
- if (reply.sfGood)
- {
- FSpDelete(&reply.sfFile);
- if (FSpCreate(&reply.sfFile, 'VIP@', 'TEXT', reply.sfScript) != noErr)
- {
- printf("File create error\n");
- break;
- }
- if (FSpOpenDF(&reply.sfFile, fsCurPerm, &fileRefNum) != noErr)
- {
- printf("File open error\n");
- }
-
- Rewind();
-
- while (ReadBlock(buffer) == OK)
- {
- count = BLOCKSIZE;
- if (FSWrite(fileRefNum, &count, buffer) != noErr)
- {
- printf("File write error\n");
- break;
- }
- }
- FSClose(fileRefNum);
- }
- break;
-
- case DUMP_FILE_ITEM: /* write file to tape*/
-
- StandardGetFile(NULL, -1, NULL, &reply);
- if (reply.sfGood)
- {
- if (FSpOpenDF(&reply.sfFile, fsCurPerm, &fileRefNum) != noErr)
- {
- printf("File open error\n");
- }
-
- Rewind();
-
- count = BLOCKSIZE;
- while (FSRead(fileRefNum, &count, buffer) == noErr)
- {
- if (WriteBlock(buffer) != OK)
- {
- printf("Tape write error\n");
- break;
- }
- }
- if (count) /* partial block */
- if (WriteBlock(buffer) != OK) printf("Tape write error\n");
- FSClose(fileRefNum);
- WriteMark(1);
- }
- break;
-
- }
- return;
- }
-
-
- short SearchDirectory(long parID, short vRefNum,
- short (*fileFunc)(Str255), short (*dirFunc)(Str255))
- {
- CSParam pb;
- FSSpec theResults[MAX_MATCHES];
- char workBuf[MATCH_SPACE];
- HFileInfo spec1, spec2;
- OSErr err;
- Boolean done;
- short loopy;
- HFileInfo fInfo;
- Str255 fullName;
- DirInfo cRec;
-
- pb.ioCompletion = NULL;
- pb.ioNamePtr = NULL;
- pb.ioVRefNum = vRefNum;
- pb.ioMatchPtr = theResults;
- pb.ioReqMatchCount = MAX_MATCHES;
- pb.ioSearchBits = fsSBFlParID + fsSBFlAttrib;
- pb.ioSearchInfo1 = (CInfoPBPtr)&spec1;
- pb.ioSearchInfo2 = (CInfoPBPtr)&spec2;
- pb.ioSearchTime = -1;
- pb.ioCatPosition.initialize = 0;
- pb.ioOptBuffer = workBuf;
- pb.ioOptBufSize = MATCH_SPACE;
-
- memset(&spec1, 0, sizeof(spec1));
- spec1.ioFlParID = parID;
- memset(&spec2, 0, sizeof(spec2));
- spec2.ioFlParID = parID;
- spec2.ioFlAttrib = IOFADIRECTORY; /* files */
-
- do
- {
- err = PBCatSearchSync(&pb);
- done = (err == eofErr);
- if (((err == noErr) || done) && (pb.ioActMatchCount > 0))
- {
- for (loopy = 0; loopy < pb.ioActMatchCount; loopy++)
- {
- FullFileName(fullName, theResults[loopy].name,
- theResults[loopy].vRefNum, theResults[loopy].parID);
- (*fileFunc)(fullName);
- }
- }
- } while (!done);
-
- pb.ioCatPosition.initialize = 0;
- spec1.ioFlAttrib = IOFADIRECTORY; /* directories */
-
- do
- {
- err = PBCatSearchSync(&pb);
- done = (err == eofErr);
- if (((err == noErr) || done) && (pb.ioActMatchCount > 0))
- {
- for (loopy = 0; loopy < pb.ioActMatchCount; loopy++)
- {
- FullFileName(fullName, theResults[loopy].name,
- theResults[loopy].vRefNum, theResults[loopy].parID);
- (*dirFunc)(fullName);
-
- memset(&cRec, 0, sizeof(cRec));
- cRec.ioNamePtr = theResults[loopy].name;
- cRec.ioVRefNum = theResults[loopy].vRefNum;
- cRec.ioDrDirID = theResults[loopy].parID;
- PBGetCatInfo(&cRec, FALSE);
- SearchDirectory(cRec.ioDrDirID, cRec.ioVRefNum, fileFunc, dirFunc);
- }
- }
- } while (!done);
- return noErr;
- }
-
-
-
-